package com.gitee.wsl.ext.list

/**
 * See [List.subList], but if input is out of bounds then null is returned instead.
 */
fun <T> List<T>.subListOrNull(fromIndex: Int, toIndex: Int): List<T>? {
    if (fromIndex < 0 || /*toIndex is exclusive, hence minus 1*/ toIndex - 1 > lastIndex) {
        return null
    }

    return subList(fromIndex = fromIndex, toIndex = toIndex)
}